package com.caiyi.financial.nirvana.sms.controller;


import com.caiyi.financial.nirvana.sms.entity.SmsBlacklist;
import com.caiyi.financial.nirvana.sms.querybean.QueryBlacklistBean;
import com.caiyi.financial.nirvana.sms.querybean.SendParamsQueryBean;
import com.caiyi.financial.nirvana.sms.service.SmsBlacklistService;
import com.caiyi.financial.nirvana.sms.util.CommUtil;
import com.youyu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Set;

@Api(description = "黑名单管理")
@RestController
@CrossOrigin
@RequestMapping("sms/admin/blacklist")
public class BlacklistController {

    @Autowired
    private SmsBlacklistService blacklistService;

    @ApiOperation(value = "添加Blacklist详情", notes = "添加Blacklist详情描述")
    @ApiImplicitParam(name = "smsBlacklist", value = "平台黑名单", required = true, dataType = "SmsBlacklist")
    @PostMapping("/addBlacklist")
    public Result addBlacklist(@RequestBody SmsBlacklist smsBlacklist) {
        return Result.ok(blacklistService.addBlacklist(smsBlacklist));
    }

    @ApiOperation(value = "平台黑名单导入", notes = "平台黑名单导入")
    @ApiImplicitParam(name = "file", value = "导入黑名单", required = true)
    @PostMapping("/importBlackPhone")
    public Result importBlackPhone(@RequestParam("file") MultipartFile file) throws Exception {
        Set<String> phones = CommUtil.readLines(file.getInputStream());
        return Result.ok(blacklistService.importBlackPhone(phones));
    }

    @ApiOperation(value = "平台黑名单导入提交", notes = "平台黑名单导入提交")
    @ApiImplicitParam(name = "sendParamsQueryBean", value = "导入黑名单提交", required = true, dataType = "SendParamsQueryBean")
    @PostMapping("/submitBlackPhone")
    public Result submitBlackPhone(@RequestBody SendParamsQueryBean sendParamsQueryBean) throws Exception {
        return Result.ok(blacklistService.submitBlackPhone(sendParamsQueryBean));
    }

    @ApiOperation(value = "删除Blacklist详情", notes = "删除Blacklist")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "黑名单id", dataType = "int", paramType = "query", required = true)})
    @PostMapping("/deleteBlacklist")
    public Result deleteBlacklist(Integer id) {
        return Result.ok(blacklistService.deleteBlacklist(id));
    }

    @ApiOperation(value = "更新Blacklist详情", notes = "更新Blacklist")
    @ApiImplicitParam(name = "smsBlacklist", value = "平台黑名单", required = true, dataType = "SmsBlacklist")
    @PostMapping("/updateBlacklist")
    public Result updateBlacklist(@RequestBody SmsBlacklist smsBlacklist) {
        return Result.ok(blacklistService.updateBlacklist(smsBlacklist));
    }

    @ApiOperation(value = "根据params查找Blacklist详情", notes = "根据params查找Blacklist详情描述")
    @ApiImplicitParams({@ApiImplicitParam(name = "bean", value = "查找黑名单参数", dataType = "QueryBlacklistBean", paramType = "body"),

    })
    @PostMapping("/getBlacklistByParams")
    public Result getBlacklistByParams(@RequestBody QueryBlacklistBean bean) {
        return Result.ok(blacklistService.getBlacklistByParams(bean));
    }
}
